<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title></title>
    <div>
        <h3>常量</h3>
        <p>摄像头支持的分辨率(supportedImageResolutions): <span id="supportedImageResolutions"></span></p>
        <p>摄像头支持的照片格式(supportedImageFormats): <span id="supportedImageFormats"></span></p>
        <p>摄像头支持的视频格式(supportedVideoFormats): <span id="supportedVideoFormats"></span></p>
    </div>
    <div>
        <h3>方法</h3>
        <p onclick="caputure()">调取摄像头拍照</p>
        <p onclick="videoCapture()">调取摄像头录像</p>
        <p onclick="stopCapture()">停止摄像头录像</p>
    </div>
    <script type="text/javascript">
        var supportedImageResolutions = document.getElementById('supportedImageResolutions');
        var supportedImageFormats = document.getElementById('supportedImageFormats');
        var supportedVideoFormats = document.getElementById('supportedVideoFormats');

        // 属性

        // 方法
        // 扩展API加载完毕后调用onPlusReady回调函数
        document.addEventListener("plusready", onPlusReady, false);
        // 扩展API加载完毕，现在可以正常调用扩展API
        function onPlusReady() {
            var cmr = plus.camera.getCamera();
            console.log(cmr);
            supportedImageResolutions.innerText = cmr.supportedImageResolutions;
            supportedImageFormats.innerText = cmr.supportedImageFormats;
            supportedVideoFormats.innerText = cmr.supportedVideoFormats;
        }

        // 调取摄像头拍照
        function caputure() {
            var cmr = plus.camera.getCamera();
            var res = cmr.supportedImageResolutions[0];
            var fmt = cmr.supportedImageFormats[0];
            console.log("Resolution: "+res+", Format: "+fmt);
            cmr.captureImage( function( path ){
                    alert( "Capture image success: " + path );
                },
                function( error ) {
                    alert( "Capture image failed: " + error.message );
                },
                {resolution:res,format:fmt}
            );
        }

        // 调取摄像头录像
        function videoCapture(){
            var cmr = plus.camera.getCamera();
            var res = cmr.supportedVideoResolutions[0];
            var fmt = cmr.supportedVideoFormats[0];
            console.log("Resolution: "+res+", Format: "+fmt);
            cmr.startVideoCapture( function( path ){
                    alert( "Capture video success: " + path );
                },
                function( error ) {
                    alert( "Capture video failed: " + error.message );
                },
                {resolution:res,format:fmt}
            );
        }

        // 停止摄像头录像
        function stopCapture(){
            var cmr = plus.camera.getCamera();
            console.log("stopCapture");
            cmr.stopVideoCapture();
        }

    </script>
</head>
<body>

</body>
</html>